Ext.define('Triends.view.Sendmessage', {
	extend: 'Ext.Panel',
	xtype: 'sendmessage',
	id: 'send',
	config: {
    	modal: true,
    	top: '10%',
    	left: '50%',
    	layout: 'vbox',
    	style: 'margin-left:-150px',
		hideOnMaskTap: true,
		width: 300,
		height: 350,
		listeners: {
			hide: function() {
				this.destroy();
			}
		},
//		hidden: true,
    	items: [{
    		xtype: 'titlebar',
    		docked: 'top',
    		height: 50,
    		title: 'Message'
    	},
    	{
    		xtype: 'panel',
    		docked: 'top',
    		height: 40,
    		style: {'background': '-webkit-gradient(linear, left top, left bottom, from(#FEFCFC), to(#E9E8E8))'},
    		items:[{
    			id: 'getterpanel',
    			xtype: 'panel',
    			padding: 5,
	    		tpl: [
					"<font size='2'><b>받는 사람 :&nbsp;&nbsp;{Getter}</b></font>" //ID대신 OtherName필요합니다.
				]
    		}]
    	},
    	{
    		xtype: 'panel',
    		height: 210,
    		items: [{
	    		xtype: 'textareafield',
	    		height: 220,
	    		maxRows: 8,
	    		id: 'msgcontents'
    		}]
    	},
    	{
    		xtype: 'button',
    		docked: 'bottom',
    		text: 'send',
    		handler: function() {
    			Ext.Viewport.setMasked({
					xtype: 'loadmask',
    				indicator: true
				});		
    			var senderID = Ext.getCmp('getterpanel').getData().SenderID;
    			var sender = Ext.getCmp('getterpanel').getData().Sender;
    			var getterID = Ext.getCmp('getterpanel').getData().GetterID;
    			var getter = Ext.getCmp('getterpanel').getData().Getter;
    			var msg = Ext.getCmp('msgcontents').getValue();
    			
    			var send = Ext.getCmp('send');
				send.destroy();
    			
    			Ext.Ajax.request({
            		url: 'http://itscreater.cafe24.com/Triends/Sendmessage.jsp',
            		params: {
            			senderID: senderID,
            			sender: sender,
            			getterID: getterID,
            			getter: getter,
            			msg : msg
            		},
            		useDefaultXhrHeader: false,
//            		reader: {type: 'json'},
//            		callbackKey: 'callback',
            		success: function(response) {
            			//MessageStore.load(); // 보낸쪽지함 있을 시 살려야함
            		}
            	});
            	
            	Ext.Viewport.setMasked(false);
				
				navigator.notification.confirm(
					'전송되었습니다.',
					function(){},
					'알림',
					'확인'
				)
    		}
    	}]
	}
});